<%-- homeContent.jsp - 首页纯内容页 --%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<style>
    /* 确保页面根元素充满视口 */
    html, body {
        height: 100%;
        margin: 0;
        padding: 0;
    }

    /* 首页主容器，垂直排列，占满100vh */
    .dashboard-container {
        display: flex;
        flex-direction: column;
        max-height: 90vh;
        padding: 20px;
        box-sizing: border-box;
        gap: 20px;
    }

    /* 顶部卡片行 */
    .stats-row {
        display: flex;
        justify-content: center;
        gap: 5px;
        padding-bottom: 10px;
        overflow-x: auto; /* 确保小屏幕可滚动 */
    }

    /* 滚动条样式 */
    .stats-row::-webkit-scrollbar {
        height: 6px;
    }

    .stats-row::-webkit-scrollbar-thumb {
        background-color: rgba(0, 0, 0, 0.1);
        border-radius: 3px;
    }

    /* 数据统计卡片样式 */
    .stat-card {
        flex: 0 0 auto;
        width: 20%;
        background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
        border-radius: 12px;
        padding: 20px;
        margin-top: 20px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
        transition: transform 0.3s ease;
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
        border: 1px solid #e9ecef;
    }

    .stat-card:hover {
        transform: translateY(-5px);
    }

    .stat-card .card-icon {
        font-size: 36px;
        margin-bottom: 15px;
        color: #4dabf7;
    }

    .stat-card h3 {
        margin: 0 0 10px 0;
        font-size: 16px;
        color: #6c757d;
        font-weight: 500;
    }

    .stat-card .stat-value {
        font-size: 32px;
        font-weight: 700;
        margin: 0;
        color: #212529;
    }

    /* 卡片颜色 */
    .stat-card.users .card-icon {
        color: #48bb78;
    }

    .stat-card.books .card-icon {
        color: #3b82f6;
    }

    .stat-card.borrows .card-icon {
        color: #f97316;
    }

    .stat-card.returns .card-icon {
        color: #ef4444;
    }

    /* 图表行 */
    .charts-row {
        display: flex;
        gap: 20px;
        flex-grow: 1;
        min-height: 0;
    }

    .chart-card {
        flex: 1;
        background: #fff;
        border-radius: 12px;
        padding: 20px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
        border: 1px solid #e9ecef;
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    .chart-card h3 {
        margin: 0 0 15px 0;
        font-size: 18px;
        color: #343a40;
        font-weight: 600;
        border-bottom: 1px solid #f1f3f5;
        padding-bottom: 10px;
    }

    /* 图表容器 - 关键：设置明确的最小高度 */
    .chart-container {
        flex-grow: 1;
        background-color: #fafafa;
        border-radius: 8px;
        overflow: hidden;
        min-height: 300px; /* 确保图表有足够高度 */
    }

    /* 响应式调整 */
    @media (max-width: 768px) {
        .charts-row {
            flex-direction: column;
        }
        .stat-card {
            width: 180px;
        }
        .chart-container {
            min-height: 250px;
        }
    }
</style>

<!-- 引入本地ECharts (使用JSTL的contextPath确保路径正确) -->
<script src="<c:url value='/static/echarts/echarts.min.js'/>"></script>

<div class="dashboard-container">
    <%-- 1. 核心数据统计区 --%>
    <div class="stats-row">
        <!-- 用户总数卡片 -->
        <div class="stat-card users">
            <div class="card-icon">😋</div>
            <h3>用户总数</h3>
            <p class="stat-value">3</p>
        </div>
        <!-- 书本数卡片 -->
        <div class="stat-card books">
            <div class="card-icon">😊</div>
            <h3>书本总数</h3>
            <p class="stat-value">10</p>
        </div>
        <!-- 总借阅卡片 -->
        <div class="stat-card borrows">
            <div class="card-icon">🤗</div>
            <h3>总借阅次数</h3>
            <p class="stat-value">10</p>
        </div>
        <!-- 总归还卡片 -->
        <div class="stat-card returns">
            <div class="card-icon">😠</div>
            <h3>总归还次数</h3>
            <p class="stat-value">7</p>
        </div>
    </div>

    <%-- 2. 图表统计区 --%>
    <div class="charts-row">
        <!-- 近半年借阅量图表 -->
        <div class="chart-card">
            <h3>近半年借阅量统计</h3>
            <div id="borrowChart" class="chart-container"></div>
        </div>
        <!-- 近半年归还量图表 -->
        <div class="chart-card">
            <h3>近半年归还量统计</h3>
            <div id="returnChart" class="chart-container"></div>
        </div>
    </div>
</div>

<script type="text/javascript">
    // 等待页面完全加载（包括ECharts脚本）
    window.onload = function() {
        // 检查ECharts是否加载成功
        if (typeof echarts === 'undefined') {
            console.error('ECharts未加载成功，请检查文件路径');
            return;
        }

        // --- 初始化借阅量图表 ---
        const borrowChartDom = document.getElementById('borrowChart');
        if (borrowChartDom) {
            const borrowChart = echarts.init(borrowChartDom);

            const borrowOption = {
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['借阅量'],
                    bottom: 0
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '15%',
                    containLabel: true
                },
                xAxis: {
                    type: 'category',
                    data: ['1月', '2月', '3月', '4月', '5月', '6月']
                },
                yAxis: {
                    type: 'value',
                    beginAtZero: true
                },
                series: [
                    {
                        name: '借阅量',
                        type: 'bar',
                        data: [120, 200, 150, 80, 70, 110],
                        itemStyle: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                { offset: 0, color: '#3b82f6' },
                                { offset: 1, color: '#60a5fa' }
                            ])
                        }
                    }
                ]
            };

            borrowChart.setOption(borrowOption);
            // 监听窗口大小变化
            window.addEventListener('resize', () => borrowChart.resize());
        }

        // --- 初始化归还量图表 ---
        const returnChartDom = document.getElementById('returnChart');
        if (returnChartDom) {
            const returnChart = echarts.init(returnChartDom);

            const returnOption = {
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['归还量'],
                    bottom: 0
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '15%',
                    containLabel: true
                },
                xAxis: {
                    type: 'category',
                    data: ['1月', '2月', '3月', '4月', '5月', '6月']
                },
                yAxis: {
                    type: 'value',
                    beginAtZero: true
                },
                series: [
                    {
                        name: '归还量',
                        type: 'line',
                        smooth: true,
                        data: [60, 160, 100, 110, 40, 90],
                        itemStyle: {
                            color: '#ef4444'
                        },
                        lineStyle: {
                            width: 3
                        }
                    }
                ]
            };

            returnChart.setOption(returnOption);
            // 监听窗口大小变化
            window.addEventListener('resize', () => returnChart.resize());
        }
    };
</script>
